package com.platform.web.controller.module;

import java.util.List;
import com.platform.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.platform.common.annotation.Log;
import com.platform.common.enums.BusinessType;
import com.platform.module.domain.HeatUser;
import com.platform.module.service.IHeatUserService;
import com.platform.common.core.controller.BaseController;
import com.platform.common.core.domain.AjaxResult;
import com.platform.common.utils.poi.ExcelUtil;
import com.platform.common.core.page.TableDataInfo;

/**
 * 供热用户信息Controller
 * 
 * @author wangqi
 * @date 2020-08-19
 */
@Controller
@RequestMapping("/module/user")
public class HeatUserController extends BaseController
{
    private String prefix = "module/user";

    @Autowired
    private IHeatUserService heatUserService;

    @RequiresPermissions("module:user:view")
    @GetMapping()
    public String user()
    {
        return prefix + "/user";
    }

    /**
     * 查询供热用户信息列表
     */
    @RequiresPermissions("module:user:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HeatUser heatUser)
    {
        startPage();
        List<HeatUser> list = heatUserService.selectHeatUserList(heatUser);
        return getDataTable(list);
    }

    /**
     * 导出供热用户信息列表
     */
    @RequiresPermissions("module:user:export")
    @Log(title = "供热用户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HeatUser heatUser)
    {
        List<HeatUser> list = heatUserService.selectHeatUserList(heatUser);
        ExcelUtil<HeatUser> util = new ExcelUtil<HeatUser>(HeatUser.class);
        return util.exportExcel(list, "user");
    }

    /**
     * 新增供热用户信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存供热用户信息
     */
    @RequiresPermissions("module:user:add")
    @Log(title = "供热用户信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HeatUser heatUser)
    {
        heatUser.setCreateBy(ShiroUtils.getLoginName());
        return toAjax(heatUserService.insertHeatUser(heatUser));
    }

    /**
     * 修改供热用户信息
     */
    @GetMapping("/edit/{usId}")
    public String edit(@PathVariable("usId") Long usId, ModelMap mmap)
    {
        HeatUser heatUser = heatUserService.getById(usId);
        mmap.put("heatUser", heatUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存供热用户信息
     */
    @RequiresPermissions("module:user:edit")
    @Log(title = "供热用户信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HeatUser heatUser)
    {
        heatUser.setUpdateBy(ShiroUtils.getLoginName());
        return toAjax(heatUserService.updateHeatUser(heatUser));
    }

    /**
     * 删除供热用户信息
     */
    @RequiresPermissions("module:user:remove")
    @Log(title = "供热用户信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(heatUserService.deleteHeatUserByIds(ids));
    }
}
